<div class="loader"></div>
<div class="row filter-form-container">
{{ Form::open(array('url' => $base, 'id' => 'form-filter')) }}
<div class='filter-form-group row'>
	<div class="form-group col-md-4">
		@if ( !empty($companies) )
			{{ Form::label('filter_company', $text_filter_company) }}
			{{ Form::select('filter_company', $companies, Input::get('filter_company'), array('class' => 'form-control')) }}
		@endif
		
		{{ Form::label('filter_order_ids', $text_filter_order_ids) }}<br/>
		{{ Form::textarea('filter_order_ids', Input::get('filter_order_ids'), ['size' => '50x3', 'placeholder' => $text_filter_line_separated ]) }}
		
		@if ( !empty($statuses) )
			{{ Form::label('filter_status', $text_filter_status) }}
			
			@if ( Input::has('filter_status') )
				{{ Form::select('filter_status', $statuses, Input::get('filter_status'), array('class' => 'form-control')) }}
			@else
				{{ Form::select('filter_status', $statuses, 'all', array('class' => 'form-control')) }}
			@endif
		@endif
	</div>
	<div class="form-group col-md-4">
		<strong>{{ $text_filter_order_date }}</strong>
		<div class="row" style="padding-top: 5px;">
			<div class='col-md-6'>
				<div class="form-group" style="margin-bottom: 3px;">
					{{ Form::text('filter_order_date_from', Input::get('filter_order_date_from'), array('class' => 'form-control', 'placeholder' => $text_filter_order_date_from )) }}
				</div>
			</div>
			<div class='col-md-6'>
				<div class="form-group" style="margin-bottom: 3px;">
					{{ Form::text('filter_order_date_to', Input::get('filter_order_date_to'), array('class' => 'form-control', 'placeholder' => $text_filter_order_date_to)) }}
				</div>
			</div>
		</div>

		{{ Form::label('filter_item_ids', $text_filter_item_ids) }}<br/>
		{{ Form::textarea('filter_item_ids', Input::get('filter_item_ids'), ['size' => '45x3', 'placeholder' => $text_filter_line_separated ]) }}
		<br/>
		
		@if ( !empty($statuses) )
			{{ Form::label('filter_item_status', $text_filter_item_status) }}
			
			@if ( Input::has('filter_item_status') )
				{{ Form::select('filter_item_status', $statuses, Input::get('filter_item_status'), array('class' => 'form-control')) }}
			@else
				{{ Form::select('filter_item_status', $statuses, 'all', array('class' => 'form-control')) }}
			@endif
		@endif
	</div>
	<div class="form-group col-md-4">
		{{ Form::label('filter_employee_id', $text_employee_id) }}
		{{ Form::text('filter_employee_id', Input::get('filter_employee_id'), array('class' => 'form-control', 'id'=>'filter_employee_id')) }}
		
		{{ Form::label('filter_employee_email', $text_filter_employee_email) }}
		{{ Form::email('filter_employee_email', Input::get('filter_employee_email'), array('class' => 'form-control', 'id'=>'filter_employee_email')) }}

		<strong>{{ $text_employee_name }}</strong>
		<div class="row">
			<div class='col-md-6'>
				<div class="form-group">
					{{ Form::text('filter_employee_firstname', Input::get('filter_employee_firstname'), array('class' => 'form-control', 'id'=>'filter_employee_firstname', 'placeholder' => $text_firstname)) }}
				</div>
			</div>
			<div class='col-md-6'>
				<div class="form-group">
					{{ Form::text('filter_employee_lastname', Input::get('filter_employee_lastname'), array('class' => 'form-control' , 'id'=>'filter_employee_lastname', 'placeholder' => $text_lastname )) }}
				</div>
			</div>
		</div>
	</div>
	<div class="clearfix"></div>
</div>
	
	{{-- Form Filter Buttons --}}
	<div class="filter-btn-row row">
		{{ HTML::link(URL::to($base), $text_filter, array('class' => 'btn btn-default', 'id'=> 'filter')) }}
		{{ HTML::link(URL::to('/order/export-list/1'), 'Generate List' , array('class' => 'btn btn-default btn-export', 'id'=> 'export')) }}
		{{ HTML::link(URL::to('/order/export-options-list/1'), 'Generate Option List' , array('class' => 'btn btn-default btn-export', 'id'=> 'export-options')) }}
		<span class="file-loader-progress"></span>
	</div>
{{ Form::close() }}
</div>
<p>&nbsp</p>
<div class="order-list panel-group" id="accordion" role="tablist" aria-multiselectable="true">
@foreach($results AS $key=>$value)
	<div class="row list-row">
	<div class="panel panel-default">
		<div class="panel-heading order_status_{{ $value->status }} " role="tab" id="o-{{ $value->id }}">
		<a class="header-po-link" poid="{{ $value->id }}" data-toggle="collapse" data-parent="#accordion" href="#o-detail-{{ $value->id }}" aria-expanded="false" aria-controls="o-detail-{{ $value->id }}">
			{{ strtoupper($list_sales_order_id) }}: {{ $value->id }} <small>({{ $statuses[$value->status] }})</small>
		</a>
		</div>
	</div>
	<div id="o-detail-{{ $value->id }}" class="panel-collapse collapse order-info-box" role="tabpanel" aria-labelledby="o-{{ $value->id }}" >
		<div class="panel-body" id="o-detail-body-{{ $value->id }}">
				<div role="tabpanel">
					  <!-- Nav tabs -->
					  <ul class="nav nav-tabs" role="tablist">
					    <li role="presentation" class="active"><a href="#order-info-{{ $value->id }}" aria-controls="home" role="tab" data-toggle="tab">{{ $list_info }}</a></li>
					    <li role="presentation"><a href="#order-status-{{ $value->id }}" aria-controls="profile" role="tab" data-toggle="tab">{{ $list_items_per_status }}</a></li>
					    <li role="presentation"><a href="#order-set-{{ $value->id }}" aria-controls="messages" role="tab" data-toggle="tab">{{ $list_items_per_set }}</a></li>
					    
					    @if ( !is_null($value->topup) )
					    	<li role="presentation"><a href="#order-topup-{{ $value->id }}" aria-controls="messages" role="tab" data-toggle="tab">{{ $list_topup_info }}</a></li>
					    @endif
					  </ul>
					
					  <!-- Tab panes -->
					  <div class="tab-content">
					  	{{-- Order Info --}}
					    <div role="tabpanel" class="tab-pane active" id="order-info-{{ $value->id }}">
					    		<table class="table table-bordered table-responsive">
									<thead>
										<tr>
											<th colspan="2">{{ $list_order_details }}</th>
											<th colspan="2">{{ $list_totals }}</th>
										</tr>
									</thead>
									<tbody class="table-striped">
										<tr>
											<th><strong>{{ $list_sales_order_id }}</strong></th><td>{{ $value->id }}</td>
											<th><strong>{{ $list_payment_method }}</strong></th><td>{{ $value->payment_method }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_company }}</strong></th><td>{{ $value->company_code }}</td>
											<th><strong>{{ $list_gross }}</strong></th><td>{{ number_format($value->peso, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_branch }}</strong></th><td>{{ $value->branch_code }}</td>
											<th><strong>{{ $list_tax }}</strong></th><td>{{ number_format($value->tax, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_employee_number }}</strong></th><td>{{ $value->employee_number }}</td>
											<th><strong>{{ $list_delivery_fee }}</strong></th><td>{{ number_format($value->delivery_fee, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_employee_name }}</strong></th><td>{{ $value->firstname }} {{ $value->lastname }}</td>
											<th><strong>{{ $list_paid_points }}</strong></th><td>{{ number_format($value->points, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_employee_email }}</strong></th><td>{{ $value->employee_email }}</td>
											<th><strong>{{ $list_paid_topup }}</strong></th><td>{{ number_format($value->topup_total, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_status }}</strong></th><td>{{ $statuses[$value->status] }}</td>
											<th><strong>{{ $list_date_ordered }}</strong></th><td>{{ Formatter::toDateFormat( $value->created_at, 'm/d/Y h:i:s' ) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_comments }}</strong></th><td colspan="3">{{ $value->comment }}</td>
										</tr>
									</tbody>
								</table>
					    </div>
					    
					    {{-- Total Items Per Status --}}
					    <div role="tabpanel" class="tab-pane" id="order-status-{{ $value->id }}">
					    	@if ( !empty($items[(int) $value->id]['status_info']) )
					    		<div class="col-md-6" style="padding: 0;">
							    	<table class="table table-bordered">
									<thead>
										<th>{{ $list_status }}</th>
										<th>{{ $list_total }}</th>
									</thead>
									<tbody class="table-striped">
									@foreach( $items[(int) $value->id]['status_info'] as $status => $total )
										<tr>
											<td>{{ $statuses[$status] }}</td>
											<td>{{ $total }}</td>
										</tr>
									@endforeach
									</tbody>
								</table>
								</div>
								<div class="clearfix"></div>
					    	@else
					    		N/A
					    	@endif
					    </div>

					    {{-- Items Per Set --}}
					    <div role="tabpanel" class="tab-pane" id="order-set-{{ $value->id }}">
					    		@foreach ( $items[(int) $value->id] as $set => $item )
									@if ( $set != 'status_info' )
										<h4 style="font-weight: bold; display: bl">SET: {{ strtoupper($sizes[$set]) }}</h4>
										<table class="table table-bordered table-striped">
											<thead>
												<tr>
													<td>{{ $list_id }}</td>
													<td>{{ $list_product_name }}</td>
													<td>{{ $list_product_model }}</td>
													<td>{{ $list_product_category }}</td>
													<td>{{ $list_product_options }}</td>
													<td>{{ $list_status }}</td>
													<td>{{ $list_benstore_price }}</td>
													<td>{{ $list_quantity }}</td>
													<td>{{ $list_peso_delivery }}</td>
													<td>{{ $list_points_delivery }}</td>
													<td>{{ $list_peso }}</td>
													<td>{{ $list_tax }}</td>
													<td>{{ $list_points }}</td>
													<td>{{ $list_topup }}</td>
													<td>{{ $list_po_date }}</td>
												</tr>
											</thead>
											<tbody class="table-striped">
											@foreach( $item['products'] as $id => $op )
												<tr>
													<td>{{ $id }}</td>
													<td>{{ $op['name'] }}</td>
													<td>{{ $op['model'] }}</td>
													<td>{{ $op['category'] }}</td>
													<td>
														<ul style="padding-left: 15px;">
														@if ( !empty($op['options']) )
															@foreach ( $op['options'] as $option )
																<li>{{ $option['value'] }} ({{ number_format($option['price'], 2) }}) - {{ $option['quantity'] }}</li>
															@endforeach
														@else
															N/A
														@endif
														<ul>
													</td>
													<td>{{ $statuses[$op['status']] }}</td>
													<td>{{ number_format($op['benstore_price'], 2) }}</td>
													<td>{{ $op['quantity'] }}</td>
													<td>{{ number_format($op['delivery_peso'], 2) }}</td>
													<td>{{ number_format($op['delivery_points'], 2) }}</td>
													<td>{{ number_format($op['peso'], 2) }}</td>
													<td>{{ number_format($op['tax'], 2) }}</td>
													<td>{{ number_format($op['points'], 2) }}</td>
													<td>{{ number_format($op['topup'], 2) }}</td>
													<td>{{ $op['po_date'] }}</td>
												</tr>
											@endforeach
											<tr class="info">
												<td colspan="7"><strong>{{ $list_total }}</strong></td>
												<td>{{ $item['total_qty'] }}</td>
												<td>{{ number_format($item['total_delivery_peso'], 2) }}</td>
												<td>{{ number_format($item['total_delivery_points'], 2) }}</td>
												<td>{{ number_format($item['total_peso'], 2) }}</td>
												<td>{{ number_format($item['total_tax'], 2) }}</td>
												<td>{{ number_format($item['total_points'], 2) }}</td>
												<td>{{ number_format($item['total_topup'], 2) }}</td>
												<td></td>
											</tr>
											<tr class="success">
											@if ( !empty($item['delivery_details']) )
												<td colspan="1"><strong>{{ $list_delivery}} 
													@if ( !empty($item['delivery_details']['method']) )
														({{ ucwords(strtolower($item['delivery_details']['method'])) }})
													@endif
													</strong>
												</td>
												<td colspan="14">
												<strong>{{ $list_address }}</strong>: 
												@if ( !empty($item['delivery_details']['address']) )
													 {{ $item['delivery_details']['address'] }}
												@else
														N/A
												@endif
												<br/>
												<strong>{{ $list_zone_name }}</strong>: 
												@if ( !empty($item['delivery_details']['zone_name']) )
													{{ $item['delivery_details']['zone_name'] }}
												@else
													N/A
												@endif
												<br/>
													<strong>{{ $list_zone_fee }}</strong>: {{ number_format($item['delivery_details']['fee'], 2) }}
												</td>
											@else
												<td colspan="1"><strong>{{ $list_delivery }}</strong></td>
												<td colspan="14">N/A</td>
											@endif
											</tr>
										</tbody>
									</table>
								@endif
							@endforeach
					    </div>
					    
						{{-- Top-up Information --}}
						@if ( !is_null($value->topup) )
						<div role="tabpanel" class="tab-pane" id="order-topup-{{ $value->id }}">
							@if ( $topup = $value->topup )
								<table class="table table-bordered table-responsive">
									<tbody class="table-striped">
										<tr>
											<th><strong>{{ $list_company }}</strong></th><td>{{ $value->company_code }}</td>
											<th><strong>{{ $list_payment_method }}</strong></th><td>{{ $value->payment_method }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_branch }}</strong></th><td>{{ $value->branch_code }}</td>
											<th><strong>{{ $list_gross }}</strong></th><td>{{ number_format($value->peso, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_employee_name }}</strong></th><td>{{ $value->firstname }} {{ $value->lastname }}</td>
											<th><strong>{{ $list_tax }}</strong></th><td>{{ number_format($value->tax, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_employee_email }}</strong></th><td>{{ $value->employee_email }}</td>
											<th><strong>{{ $list_delivery_fee }}</strong></th><td>{{ number_format($value->delivery_fee, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_date_added }}</strong></th><td>{{ Formatter::toDateFormat( $topup->created_at, 'm/d/Y h:i:s' ) }}</td>
											<th><strong>{{ $list_paid_points }}</strong></th><td>{{ number_format($value->points, 2) }}</td>
										</tr>
										<tr>
											<th><strong>{{ $list_date_updated }}</strong></th><td>{{ Formatter::toDateFormat( $topup->updated_at, 'm/d/Y h:i:s' ) }}</td>
											<th><strong>{{ $list_paid_topup }}</strong></th><td>{{ number_format($value->topup_total, 2) }}</td>
										</tr>
									</tbody>
								</table>
								
								<h4><a href="{{ URL::to('top-up') }}?filter_topup_id={{ $topup->id }}">TOP-UP ID: {{ $topup->id }} ({{ $topup_statuses[$topup->status] }})</a></h4>
									@if ( $value->topupInformation->count() )
									<table class="table table-bordered table-responsive table-striped">
										<thead>
											<tr>
												<th>{{ $list_reference_id }}</th>
												<th>{{ $list_reference_date }}</th>
												<th>{{ $list_reference_number }}</th>
												<th>{{ $list_deposit_amount }}</th>
												<th>{{ $list_image }}</th>
												<th>{{ $list_date_added }}</th>
												<th>{{ $list_comments }}</th>
											</tr>
										</thead>
										<tbody class="table-striped">
											@foreach( $value->topupInformation as $reference )
											<tr>
												<td>{{ $reference->id }}</td>
												<td>{{ $reference->date }}</td>
												<td>{{ $reference->reference_number }}</td>
												<td class="text-right">{{ number_format($reference->amount, 2) }}</td>
												<td>
												@if($value->payment_method == Constant::PAYMENT_BANK_DEPOSIT )
													<div id="view-topup-{{ $reference->id }}" class="modal fade" tabindex="-1">
													  <div class="modal-dialog">
													    <div class="modal-content">
													      <div class="modal-body text-center">
																@if ( !is_null($reference->image) )
																	{{ HTML::image(Asset::cdn($reference->image), null, array('class'=>'form-control','style'=>'500px; height: 300px; overflow: hidden;')) }}
																@else
																	{{ HTML::image('http://goodology.com/wp-content/themes/TechNews/images/img_not_available.png', null) }}
																@endif
													      </div>
													      <div class="modal-footer">
													        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
													      </div>
													    </div>
													  </div>
													</div>
													<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#view-topup-{{ $reference->id }}">
												      <i class="fa fa-search"></i>
												    </button>
												@else
													N/A
												@endif
												</td>
												<td>{{ Formatter::toDateFormat( $reference->created_at, 'm/d/Y h:i:s' ) }}</td>
												<td>{{ $reference->comment }}</td>
											</tr>
											@endforeach
										</tbody>
									</table>
									@else
										N/A
									@endif
								@endif
							<div class="clearfix"></div>
					    </div>
					    @endif

					  </div>
				</div>
		</div>
	</div>
	</div>
@endforeach
</div>
<div class="box-footer">
	<div class="col-xs-14 text-center">
		<div class="dataTables_info">Showing {{ $results->getFrom() }} to {{ $results->getTo() }} of {{ $results->getTotal() }} entries</div>
	</div>
	<div class="col-xs-14 text-center">
		<div class="no-margin">
		{{ $results->appends(Input::all())->links() }}
		</div>
	</div>
</div>
<script src="{{ Asset::bea('javascript/jquery/jquery.order-list.js') }}"></script>